<?php

class UpdateController extends CController {
	
	
	/**
	 * 更新project表
	 * 
	 * 	ALTER TABLE  `uu_project` ADD  `pro_cid` INT NOT NULL COMMENT  '分类ID',
	 *	ADD  `pro_title` VARCHAR( 50 ) NOT NULL COMMENT  '标题',
	 *	ADD INDEX (  `pro_cid` )
	 *
	 *更新数据，取每个内容的前20字作为标题
	 *所有分类都取为171或172
	 */
	public function actionUpdateProjectTable()
	{
		$model = Project::model()->findAll();
		
		//此处的ID来自于数据库中Labs的子分类
		$rand_cid = array(171,172);
		
		foreach($model as $data)
		{
			$title = UtilTools::strSlice(strip_tags($data->pro_introduce),0,20);
			$cid = array_rand($rand_cid);		
			
			UtilHelper::dump($data->attributes);
			
			$data->pro_title = $title;
			$data->pro_cid = $rand_cid[$cid];
			
			if($data->save()){
				echo "OK";
			}else{
				echo "Fail";
			}
			
			UtilHelper::dump($data->attributes);
			
			
		}
	}
	
}

?>